<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">编辑</el-button>
<!--      <el-button @click="to_all(row)" size="small">管理</el-button>-->
<!--      <el-button @click="to_field(row)" size="small">字段</el-button>-->
<!--      <el-button @click="to_field_where(row)" size="small">检索字段</el-button>-->
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if (!_config('this_tenant.id')){
      if(in_right_admin('Model/add')) btns['添加模型'] = function(){ iframe('model/edit', {width: '650px'}) }
      if(in_right_admin('Model/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }
    }

    let forms_config = {};
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left'},
      name: {name:'name', label:'模型名',width:'120px'},
      alias: {name:'alias', label:'别名', width:'120px'},
      info: {name:'info', label:'简介', min_width:'80px'},
      link_model: {name:'link_model', label:'关联模型', min_width:'120px'},
      link_order: {name:'link_order', label:'订单系统', type:'radio_switch',  width:'70px'},
      link_user: {name:'link_user', label:'用户系统', type:'radio_switch',  width:'70px'},
      need_sku: {name:'need_sku', label:'规格系统', type:'radio_switch',  width:'70px'},
      need_additional: {name:'need_additional', label:'定制系统', type:'radio_switch',  width:'70px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'140px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/model/'+(is_del?'recycle':'list'),
        title: "模型列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('Model/edit') && ~[0,row.tenant_id].indexOf(this.admin_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      this.iframe('edit?'+s94Mjs.param_encode(param))
    },
    to_all(row){
      this.$router.push('all?id='+row.id);
    },
    to_field(row){
      this.iframe('/model_field/index?model_id='+row.id);
    },
    to_field_where(row){
      this.iframe('/model_field_where/index?model_id='+row.id);
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
